package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.ProductVo;
import com.zzyl.vo.retreat.DeviceVo;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
@Api(tags = "设备管理")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("syncProductList")
    public ResponseResult getDeviceList(){
        deviceService.qureyDeviceList();
        return ResponseResult.success();
    }
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> getAllProduct(){
        List<ProductVo> productVos = deviceService.getAllProduct();
        return ResponseResult.success(productVos);
    }
    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }
    @GetMapping("/pageQueryDevice")
    private ResponseResult<PageResponse<DeviceVo>> getpageDevice(DevicePageQueryDto devicePageQuery){
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQuery);
        return ResponseResult.success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    private ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    private ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDevicePropertyStatus(@RequestBody DeviceVo deviceDto){
        return ResponseResult.success(deviceService.queryDevicePropertyStatus(deviceDto));
    }
    @PostMapping("/QueryThingModelPublished")
    private ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> queryThingModelPublished(@RequestBody DeviceVo deviceDto){
        return ResponseResult.success(deviceService.queryThingModelPublished(deviceDto));
    }
    @PostMapping("/UpdateDevice")
    private ResponseResult updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/DeleteDevice")
    private ResponseResult deleteDevice(@RequestBody DeviceDto deviceDto){
        deviceService.deleteDevice(deviceDto);
        return ResponseResult.success();
    }

}
